<?php


/** ensure this file is being included by a parent file */
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

class HelpDeskControllerTools extends HelpDeskController 
{
	/**
	 * constructor
	 */
	function __construct() 
	{
		parent::__construct();
		
		// Register Extra tasks
		$this->registerTask( 'list', 'display' );
		$this->registerTask( 'unpublish', 'publish' );
	}

	/**
	 * display 
	 * @return void
	 */
	function display() 
	{
		HelpDeskRequest::setVar( 'view', 'tools' );
		HelpDeskRequest::setVar( 'layout', 'default'  );

		parent::display();
	}
	
	/**
	 * display the tool
	 * @return void
	 */
	function view() 
	{
		HelpDeskRequest::setVar( 'view', 'tools' );
		HelpDeskRequest::setVar( 'layout', 'view'  );
		parent::display();
	}

	/*
	 * remove record(s)
	 */
	function publish()
	{
		$msg = new stdClass();
		$msg->type 		= '';
		$msg->message 	= '';
		$msg->link 		= 'index2.php?option='._THISCOMPONENT.'&controller=tools&task=list';
		
		$model = $this->getModel('tools');
		
		if (!$model->publish( $msg ))
		{
			$msg->message = HelpDeskText::_('One or More Item Could not be Un-Published') . " - " . $msg->message;
		}
		else
		{
			$msg->message = HelpDeskText::_('Items Published Status Changed');
		}
				
		$this->setRedirect( $msg->link, $msg->message, $msg->type );
	}
	
	/**
	 * save ordering
	 * @return void
	 */
	function saveorder() 
	{
		$msg = new stdClass();
		$msg->type 		= '';
		$msg->message 	= '';
		$msg->link 		= 'index2.php?option='._THISCOMPONENT.'&controller=tools&task=list';
				
		$model = $this->getModel('tools');
		
		if (!$model->saveorder( $msg ))
		{
			$msg->message = HelpDeskText::_('One or More Item Could not be Ordered') . " - " . $msg->message;
		}
		else
		{
			$msg->message = HelpDeskText::_('Items Ordered');
		}
		
		$this->setRedirect( $msg->link, $msg->message, $msg->type );
	}
	
	/**
	 * redirect
	 * @return void
	 */
	function pluginmanager() 
	{
		$link = 'index2.php?option=com_mambots&filter_type=helpdesk';
		$this->setRedirect( $link );
	}
	    
}

?>